<?php

/**
 * MLEPP - ManiaLive Extending Plugin Pack
 *
 * -- MLEPP Plugin --
 * @name RelaySpectator Information
 * @date 18-03-2012
 * @version r2.0
 * @website mlepp.trackmania.nl
 * @package MLEPP
 *
 * @author The MLEPP team
 *
 * @copyright 2010 - 2012
 *
 * ---------------------------------------------------------------------
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
 * You are allowed to change things or use this in other projects, as
 * long as you leave the information at the top (name, date, version,
 * website, package, author, copyright) and publish the code under
 * the GNU General Public License version 3.
 * ---------------------------------------------------------------------
 */
 
 
namespace ManiaLivePlugins\MLEPP\RSinfo;


use ManiaLive\Utilities\Console;
use ManiaLib\Utils\TMStrings as String;
use ManiaLive\DedicatedApi\Connection;
use ManiaLive\Data\Storage;
use ManiaLive\Features\ChatCommand\Interpreter;
use ManiaLive\Features\ChatCommand\Command;
use ManiaLive\Event\Dispatcher;
use ManiaLib\Gui\Manialink;
use ManiaLive\Utilities\Logger;
use ManiaLive\Utilities\Time;
use ManiaLive\DedicatedApi\Xmlrpc\Base64;
use ManiaLive\Gui\Windowing\CustomUI;
use ManiaLive\Gui\Windowing\WindowHandler;

class RSinfo extends \ManiaLive\PluginHandler\Plugin {
/**
	 * onInit()
	 * Function called on initialisation of ManiaLive.
	 *
	 * @return void
	 */
	 
	function onInit() {
		// this needs to be set in the init section
		$this->setPublicMethod('getVersion');
		$this->setVersion('1.0');
	}

	 /**
	 * onLoad()
	 * Function called on loading of ManiaLive.
	 *
	 * @return void
	 */
	 
	function onLoad() {
		$this->enableDedicatedEvents();
		Console::println('[' . date('H:i:s') . '] [MLEPP] Plugin: RelaySpectator r' . $this->getVersion());
	}

	 /**
	 * onUnload()
	 * Function called on unloading of ManiaLive.
	 *
	 * @return void
	 */
	 
	function onUnload() {
		parent::onUnload();
		Console::println('[' . date('H:i:s') . '] [UNLOAD] [RelaySpectator] Plugin fully unloaded.');
	}
	
	function onReady() {
	$systeminfo = $this->connection->getSystemInfo();
	$PlayerList = $this->connection->getPlayerList(50,0,2);
	foreach($PlayerList AS $Player){
	//var_dump($systeminfo);
	$Player->IsServer	= (floor($Player->flags/100000) % 10) > 0 ? 1 : 0;
	$Player->IsServer	= ($Player->IsServer && $systeminfo->serverLogin != $Player->login) ? 2 : $Player->IsServer;
	if ($Player->IsServer == 2){
	Console::println('[' . date('H:i:s') . '] Relay Server connected. Login:'.$Player->login.' NickName: '.$Player->nickName.'');
			$connection = Connection::getInstance();
			$connection->sendHideManialinkPage($Player->login, true);
	}
	}
	}
		
}
?>